<?php
namespace Api\Controller;

use Think\Controller;
use Lib\WXMicro\WXBizDataCrypt;
use Think\Crypt\Driver\Des;
use Lib\Aliyun\Sms\Sms;

class IndexController extends Controller
{

    public function index()
    {
        $key = '30819c300d06092a864886f70d010101050003818a0030818602818063ed5876022b35256544dc4c23e8fcca51a68fccb5a26d9b0a10ef6f3ff1eabc78fef6eab49f4b07a4c3ee9c2311594cdb5b1c4c22fea311c25714ca4c4fc55aed9cdeb1943822c3691ca1d7f5a59d379b10b24caed4b9a43fff1907221ff1bc0cbc22ee9887eefb0f00374e2cffc35863564a4517748c536b598626826a7c37020111';
        $pub = substr($key, - 30, 30);
        $params = array();
        $params['MERCHANTID'] = '105641000005818';
        $params['POSID'] = '015521208';
        $params['BRANCHID'] = '460000000';
        $params['ORDERID'] = '105641000005818' . '123456789000001';
        $params['PAYMENT'] = 0.01;
        $params['CURCODE'] = '01';
        $params['TXCODE'] = '530550';
        $params['REMARK1'] = '';
        $params['REMARK12'] = '';
        $params['RETURNTYPE'] = 1;
        $params['TIMEOUT'] = '';
        $params['PUB'] = $pub;
        $param = http_build_query($params);
        dump($param);
        $params['MAC'] = md5($param);
        dump($params);
        $url = 'https://ibsbjstar.ccb.com.cn/CCBIS/ccbMain?CCB_IBSVersion=V6';
        dump($url);
        $result = file_get_contents($url);
        $postdata = http_build_query($params);
        $options = array(
            'http' => array(
                'method' => 'POST',
                'header' => 'Content-type:application/x-www-form-urlencoded',
                'content' => $postdata,
                'timeout' => 15 * 60
            )
        );
       $context = stream_context_create($options);
       $result = file_get_contents($url, false, $context);
       dump($result);
    }

    public function ccbCallback()
    {}

    public function test()
    {
        Sms::sendSms('123', '123', 123, 132);
        die();
        $sign = $this->sign(array(
            'token' => 123456
        ), '123456');
        dump($sign);
        $data = "fDWxyC7CjTqU7P7LEHKkX2aVQWDauPbxEPSnCKVtwGX9jKB6BvcwBO9fPPEIbDr7cpPUqcXqApsqfkP4y%2FJyHVK2YKe5O5G0BgpI2vh%2FgNXXyFGIp6QN5bOKwrpF%2B12%2FMFIEYCCBrtzd2yT1JfS9R559WshNEjNtN6bPRYo%2FrmBOrx2CLrMNV97dv17MIovSfy4nqLK8DP7ehzLfAoA27hgXdJLlhb0vG8IQFKu0pUQ7AXdppm8XzJpBY4SgtRCiLdtDzUh3VVwzoJllm0NZgq%2B%2BDMDMjAVQhYByYRSS47CHj9Ff9R0IZD3c48OOnTc%2Fu4OlZijI0IVZJqlvQVD7wfh5zvtySvHSKwp%2FhBd6E8QNNit0cZXdJiGe5xRFjiACzwIh3aDn%2FYd7BTrWTFd63Xrwlu74DKxsHaxUsyw3fTLcaPqPTPA64Xh27jaS%2FKSEgK7%2FzZhOylkEHw2C18h7xy%2FKM3n82gTsA0RUyD6%2FZSo%3D";
        dump(urldecode($data));
        $appid = 'wx4f4bc4dec97d474b';
        $sessionKey = 'tiihtNczf5v6AKRyjwEUhQ==';
        
        $encryptedData = "CiyLU1Aw2KjvrjMdj8YKliAjtP4gsMZM
                QmRzooG2xrDcvSnxIMXFufNstNGTyaGS
                9uT5geRa0W4oTOb1WT7fJlAC+oNPdbB+
                3hVbJSRgv+4lGOETKUQz6OYStslQ142d
                NCuabNPGBzlooOmB231qMM85d2/fV6Ch
                evvXvQP8Hkue1poOFtnEtpyxVLW1zAo6
                /1Xx1COxFvrc2d7UL/lmHInNlxuacJXw
                u0fjpXfz/YqYzBIBzD6WUfTIF9GRHpOn
                /Hz7saL8xz+W//FRAUid1OksQaQx4CMs
                8LOddcQhULW4ucetDf96JcR3g0gfRK4P
                C7E/r7Z6xNrXd2UIeorGj5Ef7b1pJAYB
                6Y5anaHqZ9J6nKEBvB4DnNLIVWSgARns
                /8wR2SiRS7MNACwTyrGvt9ts8p12PKFd
                lqYTopNHR1Vf7XjfhQlVsAJdNiKdYmYV
                oKlaRv85IfVunYzO0IKXsyl7JCUjCpoG
                20f0a04COwfneQAGGwd5oa+T8yO5hzuy
                Db/XcxxmK01EpqOyuxINew==";
        
        $iv = 'r7BXXKkLb8qrSNn05n0qiA==';
        $pc = new WXBizDataCrypt($appid, $sessionKey);
        $errCode = $pc->decryptData($encryptedData, $iv, $data);
        dump($data['nickName']);
        $this->ajaxReturn($data);
    }
}